import { FastifyRequest } from 'fastify';
import { Controller, Get, Req, UseInterceptors } from '@nestjs/common';

import { PageAlias, PagePathMapping } from '@libs/common/router';
import { ReactRootView } from '@libs/server-side/decorators';
import { RenderReactInterceptor } from '@libs/server-side/interceptors';
import { ServerSideConfigService } from '@libs/server-side/services';
import { getSystemInfo } from '@libs/server-side/utils';

import { MachineInfoView } from '../views/machine-info-page.server';

@Controller('dns-info')
//@UseInterceptors(RenderReactInterceptor)
export default class DNSInfoController {
    // eslint-disable-next-line no-useless-constructor
    constructor(private readonly serverSideConfig: ServerSideConfigService) {}

    //https://registry.nlark.com/@nestjs/common/download/@nestjs/common-8.0.6.tgz?cache=0&sync_timestamp=1628151652918&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40nestjs%2Fcommon%2Fdownload%2F%40nestjs%2Fcommon-8.0.6.tgz
    //@ReactRootView(MachineInfoView, PageAlias.DemonMInfo)
    @Get('my-ip')
    public async MyIpInfo(@Req() req: FastifyRequest) {
        // this.serverSideConfig.get();
        return req?.headers['x-real-ip'] || req.raw.socket.remoteAddress;
    }
}
